#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
	struct node {
		int data;
		int lazy;
	};
	void build(vector<int>& nums, vector<node>& tree, int rt, int left, int right) {
		if (left == right) {
			tree[rt].data = nums[left];
			tree[rt].lazy = 0;
			return;
		}

		int mid = left + (right - left) / 2;
		build(nums, tree, 2 * rt + 1, left, mid);
		build(nums, tree, 2 * rt + 2, mid + 1, right);

		tree[rt].data = max(tree[2 * rt + 1].data, tree[2 * rt + 2].data);
	}
	void updataSelf(vector<node>& tree, int rt) {
		int mx = INT_MIN;
		if (rt * 2 + 1 < tree.size()) {
			mx = max(tree[rt * 2 + 1].data, mx);
		}
		if (rt * 2 + 2 < tree.size()) {
			mx = max(tree[rt * 2 + 2].data, mx);
		}
		tree[rt].data = mx;

		if (rt == 0) {
			return;
		}
		updataSelf(tree, (rt - 1) / 2);
	}
	void updata(vector<node>& tree, int rt) {
		tree[rt].data = -1;
		updataSelf(tree, (rt - 1) / 2);
	}
	int query(vector<node>& tree, int rt, int left, int right, int ql, int qr) {
		if (ql > right || qr < left) {
			return INT_MIN;
		}
		if (ql <= left && qr >= right) {
			return tree[rt].data;
		}
		int mid = left + (right - left) / 2;

		int leftMax = query(tree, rt * 2 + 1, left, mid, ql, qr);
		int rightMax = query(tree, rt * 2 + 2, mid + 1, right, ql, qr);
		return max(leftMax, rightMax);
	}
	int find_first(vector<node>& tree, int rt, int data) {
		if (tree[rt].data < data) {
			return -1;
		}
		if (rt * 2 + 1 < tree.size() && tree[rt * 2 + 1].data >= data) {
			rt = find_first(tree, rt * 2 + 1, data);
		} else if (rt * 2 + 2 < tree.size() && tree[rt * 2 + 2].data >= data) {
			rt = find_first(tree, rt * 2 + 2, data);
		}
		return rt;
	}
	int numOfUnplacedFruits(vector<int>& fruits, vector<int>& baskets) {
		vector<node> tree(4 * baskets.size());
		build(baskets, tree, 0, 0, baskets.size() - 1);

		int cnt = 0;
		for (int i = 0; i < fruits.size(); ++i) {
			int index = find_first(tree, 0, fruits[i]);
			if (index != -1) {
				++cnt;
				updata(tree, index);
			}
		}
		return fruits.size() - cnt;
	}
};
int main() {
	vector<int> fruits = { 8,20,15,92,65,68,72,26,66,24 }, baskets = { 69,29,18,99,62,63,93,69,29,17 };
	cout << Solution().numOfUnplacedFruits(fruits, baskets);
	return 0;
}